/*   1:    */ package tt.dz.common;
/*   2:    */ 
/*   3:    */ import java.io.PrintStream;
/*   4:    */ import java.text.DateFormat;
/*   5:    */ import java.text.ParseException;
/*   6:    */ import java.text.SimpleDateFormat;
/*   7:    */ import java.util.Calendar;
/*   8:    */ import java.util.Date;
/*   9:    */ import tt.dz.biz.service.common.CommonService;
/*  10:    */ 
/*  11:    */ public final class DateUtil
/*  12:    */ {
/*  13:    */   public static final String dtLong = "yyyyMMddHHmmss";
/*  14:    */   public static final String simple = "yyyy-MM-dd HH:mm:ss";
/*  15:    */   public static final String dtShort = "yyyyMMdd";
/*  16:    */   public static final String DATE_FM_YYYYMM = "yyyyMM";
/*  17:    */   private static CommonService commonService;
/*  18:    */   
/*  19:    */   public static final Date parseToDate(String dateStr)
/*  20:    */   {
/*  21: 38 */     DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/*  22:    */     try
/*  23:    */     {
/*  24: 40 */       return df.parse(dateStr);
/*  25:    */     }
/*  26:    */     catch (ParseException e)
/*  27:    */     {
/*  28: 42 */       LogUtil.error("转换日期异常，参数为dateStr=" + dateStr, e);
/*  29:    */     }
/*  30: 43 */     return null;
/*  31:    */   }
/*  32:    */   
/*  33:    */   public static final String getOrderNum()
/*  34:    */   {
/*  35: 52 */     Date date = getDBCurrentTime();
/*  36: 53 */     DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
/*  37: 54 */     return df.format(date);
/*  38:    */   }
/*  39:    */   
/*  40:    */   public static final String getDateTimeFormatter()
/*  41:    */   {
/*  42: 63 */     Date date = getDBCurrentTime();
/*  43: 64 */     DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/*  44: 65 */     return df.format(date);
/*  45:    */   }
/*  46:    */   
/*  47:    */   public static final String getDateFormatter()
/*  48:    */   {
/*  49: 74 */     Date date = getDBCurrentTime();
/*  50: 75 */     DateFormat df = new SimpleDateFormat("yyyyMMdd");
/*  51: 76 */     return df.format(date);
/*  52:    */   }
/*  53:    */   
/*  54:    */   public static final Date getDateByYMD(String formatDate)
/*  55:    */   {
/*  56: 87 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/*  57:    */     try
/*  58:    */     {
/*  59: 89 */       return sdf.parse(formatDate);
/*  60:    */     }
/*  61:    */     catch (Exception e) {}
/*  62: 91 */     return null;
/*  63:    */   }
/*  64:    */   
/*  65:    */   public static final String getStringByYMD(Date date)
/*  66:    */   {
/*  67:103 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/*  68:    */     try
/*  69:    */     {
/*  70:105 */       return sdf.format(date);
/*  71:    */     }
/*  72:    */     catch (Exception e) {}
/*  73:107 */     return null;
/*  74:    */   }
/*  75:    */   
/*  76:    */   public static final String formatyyyyMM(Date date)
/*  77:    */   {
/*  78:116 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
/*  79:    */     try
/*  80:    */     {
/*  81:118 */       return sdf.format(date);
/*  82:    */     }
/*  83:    */     catch (Exception e) {}
/*  84:120 */     return null;
/*  85:    */   }
/*  86:    */   
/*  87:    */   public static final Date getFirstDayOfMonth(Date date)
/*  88:    */   {
/*  89:130 */     Calendar calendar = Calendar.getInstance();
/*  90:131 */     calendar.setTime(date);
/*  91:132 */     calendar.set(5, 1);
/*  92:133 */     return calendar.getTime();
/*  93:    */   }
/*  94:    */   
/*  95:    */   public static final Date getLastDayOfMonth(Date date)
/*  96:    */   {
/*  97:142 */     Calendar calendar = Calendar.getInstance();
/*  98:143 */     calendar.setTime(date);
/*  99:144 */     calendar.set(5, 1);
/* 100:145 */     calendar.add(2, 1);
/* 101:146 */     calendar.add(5, -1);
/* 102:147 */     return calendar.getTime();
/* 103:    */   }
/* 104:    */   
/* 105:    */   public static final Date getCurrentDadOfLastMonth(Date date)
/* 106:    */   {
/* 107:156 */     Calendar calendar = Calendar.getInstance();
/* 108:157 */     calendar.setTime(date);
/* 109:158 */     calendar.add(2, -1);
/* 110:159 */     return calendar.getTime();
/* 111:    */   }
/* 112:    */   
/* 113:    */   public static final boolean validateIsDate(String pattern, String source)
/* 114:    */   {
/* 115:162 */     SimpleDateFormat sdf = new SimpleDateFormat(pattern);
/* 116:163 */     boolean isDate = false;
/* 117:    */     try
/* 118:    */     {
/* 119:165 */       sdf.parse(source);
/* 120:166 */       isDate = true;
/* 121:    */     }
/* 122:    */     catch (ParseException localParseException) {}
/* 123:170 */     return isDate;
/* 124:    */   }
/* 125:    */   
/* 126:    */   public static Date getDBCurrentTime()
/* 127:    */   {
/* 128:178 */     if (commonService == null) {
/* 129:179 */       commonService = (CommonService)AppContxtUtil.getBean("commonService");
/* 130:    */     }
/* 131:181 */     return commonService.getDBCurrentTime();
/* 132:    */   }
/* 133:    */   
/* 134:    */   public static void main(String[] args)
/* 135:    */   {
/* 136:185 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/* 137:186 */     System.out.println(sdf.format(getLastDayOfMonth(getDBCurrentTime())));
/* 138:    */   }
/* 139:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.common.DateUtil
 * JD-Core Version:    0.7.0.1
 */